package rabbit.client.produice;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class MyProduice {
	
	public static void main(String[] args) throws IOException, TimeoutException {
		//创建链接
		ConnectionFactory factory= new ConnectionFactory();
		factory.setHost("localhost");
		Connection connection = factory.newConnection();
		//建立通道
		Channel channel= connection.createChannel();
		//声明队列
		String queueName ="hello";
		/**
		 *  Parameters:
				queue the name of the queue   队列名称
				durable true if we are declaring a durable queue (the queue will survive a server restart) 当服务重启时队列也会启动
				exclusive true if we are declaring an exclusive queue (restricted to this connection) 声明独占队列，仅限于此链接
				autoDelete true if we are declaring an autodelete queue (server will delete it when no longer in use) 服务不使用此队列,自动删除
				arguments other properties (construction arguments) for the queue  参数队列的其他属性（构造参数）
			Returns:a declaration-confirm method to indicate the queue was successfully  用于指示队列成功的声明确认方法
			declaredThrows:java.io.IOException - if an error is encountered
		 * 
		 */
		channel.queueDeclare(queueName, false, false , false , null);
		String message = "hello rabbitMQ";
		//进行消息发布
		channel.basicPublish("", queueName, null, message.getBytes());
		//关闭通道和连接
		channel.close();
		connection.close();
	}
}
